from django.db import models
from user.models import User
from software.models import Software, SoftwareVersion
from storehouse.models import Storehouse


# Create your models here.
class UserLog(models.Model):
    user = models.ForeignKey(
        User,
        verbose_name=u"用户",
        on_delete=models.CASCADE,
        related_name='user_log',
    )
    userIP = models.GenericIPAddressField(
        verbose_name=u'用户IP地址',
        default=u'',
    )
    operate = models.CharField(
        max_length=100,
        verbose_name=u'用户操作',
        default=u'',
        null=True
    )
    createTime = models.DateTimeField(
        auto_now_add=True,
        verbose_name=u"创建时间",
    )
    lastVisiteTime = models.DateTimeField(
        auto_now=True,
        verbose_name=u"最晚访问时间",
    )
    isActive = models.BooleanField(
        verbose_name=u'是否活跃',
        default=True,
    )

    def __unicode__(self):
        return self.user

    class Meta:
        ordering = ('createTime',)


class SoftwareLog(models.Model):
    user = models.ForeignKey(
        User,
        verbose_name=u"用户",
        on_delete=models.CASCADE,
        related_name='userlog_user',
    )
    softwareVersion = models.ForeignKey(
        SoftwareVersion,
        verbose_name=u"软件记录",
        on_delete=models.CASCADE,
        related_name='softwareVersion_log',
        null=True
    )
    # storehouse = models.CharField(
    #     max_length=30,
    #     verbose_name=u'所属仓库',
    #     default=u'',
    # )
    operate = models.CharField(
        max_length=800,
        verbose_name=u'软件操作',
        default=u'',
    )
    createTime = models.DateTimeField(
        auto_now_add=True,
        verbose_name=u"创建时间",
    )
    isActive = models.BooleanField(
        verbose_name=u'是否活跃',
        default=True,
    )

    def __unicode__(self):
        return self.user

    class Meta:
        ordering = ('createTime',)


class StoreHouseLog(models.Model):
    user = models.ForeignKey(
        User,
        verbose_name=u"用户",
        on_delete=models.CASCADE,
        related_name='storehouseUser_log',
    )
    storeHouse = models.ForeignKey(
        Storehouse,
        verbose_name=u"仓库记录",
        on_delete=models.CASCADE,
        related_name='storehouse_log',
    )
    operate = models.CharField(
        max_length=800,
        verbose_name=u'仓库操作',
        default=u'',
    )
    createTime = models.DateTimeField(
        auto_now_add=True,
        verbose_name=u"创建时间",
    )
    isActive = models.BooleanField(
        verbose_name=u'是否活跃',
        default=True,
    )

    def __unicode__(self):
        return self.storeHouse

    class Meta:
        ordering = ('createTime',)
